package cn.gray.gae.job.daily.shared.domain;

import java.util.List;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;

/**
 * @author teawooo <long1795@gmail.com>
 */
@SuppressWarnings("unchecked")
public class DaoUtil {
	private static PersistenceManager m = JDOHelper.getPersistenceManagerFactory("transactions-optional").getPersistenceManager();

	public static <T, I> T get(I i) {
		return (T) m.getObjectById(i);
	}

	public static <T> List<T> getAll(Class<T> clazz) {
		Query q = m.newQuery(clazz);
		return (List<T>) q.execute();
	}

	public static <T> List<T> query(Class<T> clazz, String cond, String para, Object val) {
		Query q = m.newQuery(clazz, cond);
		q.declareParameters(para);
		return (List<T>) q.execute(val);
	}

	public static <T> void add(T t) {
		m.makePersistent(t);
	}
}
